﻿using MahApps.Metro.Controls;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using VM.Common.EventMgrLib;
using VM.Events;

namespace VM.CameraSet
{
    /// <summary>
    /// CameraSetView.xaml 的交互逻辑
    /// </summary>
    public partial class CameraSetView : MetroWindow
    {
        #region Singleton
        private static CameraSetView _instance = new CameraSetView();

        private CameraSetView()
        {
            InitializeComponent();
            this.DataContext = CameraSetViewModel.Ins;
        }
        public static CameraSetView Ins
        {
            get { return _instance; }
        }

        #endregion

        public bool IsClosed { get; set; } = true;

        public void ShowWindow()
        {
            IsClosed = false;
            this.ShowDialog();
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            EventMgr.Ins.GetEvent<HardwareChangedEvent>().Publish();
            //if (CameraSetViewModel.Ins.Timer_ContinuousAcq.IsEnabled)
            //{
            //    CameraSetViewModel.Ins.Timer_ContinuousAcq.Stop();
            //}
            e.Cancel = true;  // 取消窗口关闭
            IsClosed = true;
            this.Hide();      // 程序化隐藏窗口
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void dg_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            if (CameraSetViewModel.Ins.SelectedCameraModel == null) return;
        }
    }
}
